package com.wbt.mybatisplus.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wbt.mybatisplus.pojo.PageVo;
import com.wbt.mybatisplus.pojo.User;
import com.wbt.mybatisplus.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;


    @GetMapping("/getUser")
    public User getUser(@RequestParam int id){
        User user = userService.getById(id);
        log.info("user:{}",user.toString());
        return user;
    }

    @GetMapping("/getList")
    public List<User> getList(){
        return userService.list();
    }

    @PostMapping("/queryUser")
    public List<User> query(@RequestBody User user){
        QueryWrapper<User> qu = new QueryWrapper<>(user);
        return userService.list(qu);
    }

    @PostMapping("/findPage")
    public Page<User> findPage(@RequestBody PageVo pageVo){
        return userService.findPage(pageVo);
    }
}
